package com.hjm.project.posActivationCard.posActivationCard.controller;

import java.util.List;

import com.hjm.common.utils.Utils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.posActivationCard.posActivationCard.domain.PosActivationCard;
import com.hjm.project.posActivationCard.posActivationCard.service.IPosActivationCardService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 达标黑名单Controller
 * 
 * @author LOVE
 * @date 2020-11-28
 */
@Controller
@RequestMapping("/posActivationCard/posActivationCard")
public class PosActivationCardController extends BaseController
{
    private String prefix = "posActivationCard/posActivationCard";

    @Autowired
    private IPosActivationCardService posActivationCardService;

    @RequiresPermissions("posActivationCard:posActivationCard:view")
    @GetMapping()
    public String posActivationCard()
    {
        return prefix + "/posActivationCard";
    }

    /**
     * 查询达标黑名单列表
     */
    @RequiresPermissions("posActivationCard:posActivationCard:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PosActivationCard posActivationCard)
    {
        startPage();
        List<PosActivationCard> list = posActivationCardService.selectPosActivationCardList(posActivationCard);
        for(int i=0;i<list.size();i++){
            list.get(i).setPan(Utils.dealCard(list.get(i).getPan()));
        }
        return getDataTable(list);
    }

    /**
     * 导出达标黑名单列表
     */
    @RequiresPermissions("posActivationCard:posActivationCard:export")
    @Log(title = "达标黑名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PosActivationCard posActivationCard)
    {
        List<PosActivationCard> list = posActivationCardService.selectPosActivationCardList(posActivationCard);
        ExcelUtil<PosActivationCard> util = new ExcelUtil<PosActivationCard>(PosActivationCard.class);
        return util.exportExcel(list, "posActivationCard");
    }

    /**
     * 新增达标黑名单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存达标黑名单
     */
    @RequiresPermissions("posActivationCard:posActivationCard:add")
    @Log(title = "达标黑名单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PosActivationCard posActivationCard)
    {
        return toAjax(posActivationCardService.insertPosActivationCard(posActivationCard));
    }

    /**
     * 修改达标黑名单
     */
    @GetMapping("/edit/{pan}")
    public String edit(@PathVariable("pan") String pan, ModelMap mmap)
    {
        PosActivationCard posActivationCard = posActivationCardService.selectPosActivationCardById(pan);
        mmap.put("posActivationCard", posActivationCard);
        return prefix + "/edit";
    }

    /**
     * 修改保存达标黑名单
     */
    @RequiresPermissions("posActivationCard:posActivationCard:edit")
    @Log(title = "达标黑名单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PosActivationCard posActivationCard)
    {
        return toAjax(posActivationCardService.updatePosActivationCard(posActivationCard));
    }

    /**
     * 删除达标黑名单
     */
    @RequiresPermissions("posActivationCard:posActivationCard:remove")
    @Log(title = "达标黑名单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(posActivationCardService.deletePosActivationCardByIds(ids));
    }
}
